package com.chat.datea.adapter;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chat.datea.R;
import com.chat.datea.bean.AlbumList;
import com.chat.datea.fragment.AlbumInfoFragment;
import com.chat.datea.utils.fragment.ReplaceFragment;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by dllo on 15/10/22.
 */
public class AlbumFragment_RecyclerView_Adapter extends RecyclerView.Adapter<AlbumFragment_RecyclerView_Adapter.MyViewHolder> {
    private Context context;
    private List<AlbumList.AlbumlistEntity> albumlist;
    private FragmentManager manager;

    public AlbumFragment_RecyclerView_Adapter(Context context, List<AlbumList.AlbumlistEntity> albumlist,FragmentManager manager) {
        this.context = context;
        this.albumlist = albumlist;
        this.manager = manager;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.singer_listview_item, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.album_name.setText(albumlist.get(position).getTitle());
        Log.e("AlbumFragment_RecyclerV", albumlist.get(position).getPic_big());
        String Url = albumlist.get(position).getPic_big();
        if (!Url.equals("")) {
            Picasso.with(context).load(Url).into(holder.singer_pic);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String album_id = albumlist.get(position).getAlbum_id();
                AlbumInfoFragment albumInfoFragment = new AlbumInfoFragment(album_id);
                new ReplaceFragment(albumInfoFragment, manager, R.id.fl_content, true, null);
            }
        });
    }

    @Override
    public int getItemCount() {
        return albumlist.size();
    }


    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView album_name;
        ImageView singer_pic;

        public MyViewHolder(View itemView) {
            super(itemView);
            album_name = (TextView) itemView.findViewById(R.id.album_name);
            singer_pic = (ImageView) itemView.findViewById(R.id.singer_pic);

        }
    }
}
